home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / COMPILER / SATHER / !Sather / Library / Graphs / sa / graph_exc < prev    next >
Text File  |  1996-04-09  |  3KB  |  81 lines

  1. ---------------------------> Sather 1.1 source file <--------------------------
  2. -- Author: Benedict A. Gomes <gomes@samosa.ICSI.Berkeley.EDU>
  3. -- Copyright (C) 1995, International Computer Science Institute
  4. -- $Id: graph_exc.sa,v 1.3 1996/04/09 10:05:41 borisv Exp $
  5. --
  6. -- COPYRIGHT NOTICE: This code is provided WITHOUT ANY WARRANTY
  7. -- and is subject to the terms of the SATHER LIBRARY GENERAL PUBLIC
  8. -- LICENSE contained in the file: Sather/Doc/License of the
  9. -- Sather distribution. The license is also available from ICSI,
  10. -- 1947 Center St., Suite 600, Berkeley CA 94704, USA.
  11. -------------------------------------------------------------------
  12. class GRAPH_EXC < $STR is
  13.    -- The graph exception class. A single class is used for all library
  14.    -- graph exceptions for simplicity and sanity.  It may make
  15.    -- sense to split this class up at some future point
  16.    -- The error states are denoted by the constants beginning with err_
  17.    -- err should be set to one of these
  18.    -- 
  19.    -- Usage:
  20.    --    raise #DIGRAPH_EXC{INT}(self,"foo",g,"bad graph").missing_edge_labels;
  21.    --  
  22.    --    protect
  23.    --     ...
  24.    --    when $STR then #OUT+exception.str; end;
  25.    -- You can also check for more detailed information in the exception
  26.    -- object. In general, you can compare the "err" flag to see which
  27.    -- of the constants it is set to.
  28.    --    switch exception.err
  29.    --    when exception.err_missing_edge_labels then  -- do somethin
  30.    --    when exception.err_missing_node_labels then ...
  31.    --    else ... end;
  32.    
  33.  
  34.    const err_missing_edge_labels: STR := "All edges not labelled";
  35.    const err_missing_node_labels: STR := "All nodes not labelled";
  36.    const err_not_specified: STR := "No error specified";
  37.    
  38.    readonly attr err: STR;
  39.    -- Err should be set to one of the constant err_ strings
  40.    
  41.    readonly attr in_object: $OB; -- Object in which error occurs. 
  42.    readonly attr routine_name: STR;
  43.    readonly attr message: STR;
  44.    readonly attr graph: $STR;
  45.    
  46.    create(inobj: $OB,rout: STR,g:$STR,msg: STR): SAME is
  47.       res ::= new;
  48.       res.in_object := inobj;
  49.       res.routine_name := rout;
  50.       res.message := msg;
  51.       res.graph := g;
  52.       res.err := err_not_specified;
  53.       return res;
  54.    end;
  55.    
  56.    missing_edge_labels: SAME is err:=err_missing_edge_labels; return self end;
  57.    -- All edges were required to be labelled (possibly with weights) 
  58.    -- but some labels were missing
  59.    
  60.    missing_node_labels: SAME is err:=err_missing_node_labels; return self end;
  61.    -- All nodes were required to be labelled (possibly weighted) 
  62.    -- but some were missing
  63.    
  64.    print(file: $OSTREAM) is
  65.       file+ "\n**************************************************\n";
  66.       file+ "Graph Exception in routine "+routine_name+"\n";
  67.       file+"Error:"+err+"\n";
  68.       file+"\n"+message+"\n";
  69.       if ~void(graph) then file+graph.str;    end;
  70.       file+"\n**************************************************\n";
  71.    end;
  72.  
  73.    str: STR is 
  74.       s::= #STR_STREAM;
  75.       print(s);
  76.       return s.str;
  77.    end;
  78.    
  79. end;
  80. -------------------------------------------------------------------
  81.